Exploratory data analysis

General exploration

We display the distribution of the different SDG achievement scores, using boxplots to have an overview of the median, the range with most of the observations and the outliers.

data_question1 <- read.csv(here("scripts","data","data_question1.csv"))
data_question24 <- read.csv(here("scripts", "data", "data_question24.csv"))
data_question2 <- read.csv(here("scripts", "data", "data_question24.csv"))
data_question3_1 <- read.csv(here("scripts", "data", "data_question3_1.csv"))
data_question3_2 <- read.csv(here("scripts", "data", "data_question3_2.csv"))
data_question3_3 <- read.csv(here("scripts", "data", "data_question3_3.csv"))
Q3.1 <- read.csv(here("scripts", "data", "data_question3_1.csv"))
Q3.2 <- read.csv(here("scripts", "data", "data_question3_2.csv"))
Q3.3 <- read.csv(here("scripts", "data", "data_question3_3.csv"))
data <- read.csv(here("scripts", "data", "all_Merge.csv"))

Correlation_overall <- data_question1 %>% 
      select(population:ef_regulation)

#### boxplots ####

#for goals
#dev.off()
boxplot(Correlation_overall[2:18], 
        las = 2,            # Makes the axis labels perpendicular to the axis
        par(mar = c(5, 4, 4, 2) + 0.1),  # Adjusts the margins to fit all labels
        cex.axis = 0.7,      # Reduces the size of the axis labels
        cex.lab = 1,       # Reduces the size of the x and y labels
        notch = TRUE,       # Specifies whether to add notches or not
        main = "Merged goals boxplot", # Title of the boxplot
        xlab = "Goals",  # X-axis label
        ylab = "Score")     # Y-axis label

We see different schemes among the different goals. Indeed some are quite homogeneous with a small spread of values (e.g. overall score, goals 2 and 8) while others have a large spread of values (e.g. goals 1 and 10). Goals 1, 3, 4, 7, 9, 10 and 13 have values across all possible percentages. Goals 2, 5, 8, 13 and 17 have extreme values situated outside the 95% confidence interval. It is interesting to see that goal 8 (decent work and economic growth) is the one with smaller spread of values, whereas goal 1 (no poverty) have the higher distance between the first and the third quartile. Goal 2 (no hunger) has a tight spread of values, but with the greater amount of outliers in the smaller values, meaning hunger is similar across most countries, but when it differs it is in very bad manner.

We now display boxplpots for the different variables of the human freedom index, and then also for our other independent variables.

#for Human Freedom Index scores 
boxplot(Correlation_overall[23:34], 
        las = 2,            # Makes the axis labels perpendicular to the axis
        par(mar = c(7, 5, 2, 1)),  # Adjusts the margins to fit all labels
        cex.axis = 0.7,      # Reduces the size of the axis labels
        cex.lab = 1,       # Reduces the size of the x and y labels
        notch = TRUE,       # Specifies whether to add notches or not
        main = "Merged Human Freedom Index scores boxplot", # Title of the boxplot
        ylab = "Score")     # Y-axis label

# for the remaining variables
par(mfrow=c(2,3))
for (i in 19:22){
  boxplot(Correlation_overall[,i], main=names(Correlation_overall[i]), type="l")
}
par(mfrow=c(1,1))

We now look at the variables in a summary table to have a more precise view of the numbers.

X code year country continent region overallscore goal1 goal2 goal3 goal4 goal5 goal6 goal7 goal8 goal9 goal10 goal11 goal12 goal13 goal15 goal16 goal17
Min. : 1 Length:3565 Min. :2000 Length:3565 Length:3565 Length:3565 Min. :37.4 Min. : 0.0 Min. :16.5 Min. : 5.9 Min. : 0.0 Min. : 3.5 Min. :23.3 Min. : 0.1 Min. :40.0 Min. : 0.3 Min. : 0.0 Min. :20.3 Min. :32.9 Min. : 0.0 Min. :26.0 Min. :27.9 Min. :15.1
1st Qu.: 892 Class :character 1st Qu.:2005 Class :character Class :character Class :character 1st Qu.:55.0 1st Qu.: 44.5 1st Qu.:52.6 1st Qu.:44.3 1st Qu.: 55.6 1st Qu.:43.2 1st Qu.:53.0 1st Qu.:41.5 1st Qu.:64.0 1st Qu.:15.5 1st Qu.: 35.2 1st Qu.:55.8 1st Qu.:67.9 1st Qu.:72.9 1st Qu.:55.0 1st Qu.:51.5 1st Qu.:46.1
Median :1783 Mode :character Median :2011 Mode :character Mode :character Mode :character Median :65.5 Median : 87.4 Median :58.9 Median :70.9 Median : 80.6 Median :58.0 Median :65.3 Median :65.5 Median :70.2 Median :29.4 Median : 62.2 Median :75.3 Median :84.6 Median :90.8 Median :65.1 Median :61.4 Median :55.4
Mean :1783 NA Mean :2011 NA NA NA Mean :64.0 Mean : 71.7 Mean :58.0 Mean :64.1 Mean : 72.0 Mean :56.0 Mean :65.0 Mean :57.9 Mean :70.0 Mean :37.5 Mean : 58.3 Mean :70.3 Mean :79.3 Mean :82.1 Mean :65.0 Mean :62.6 Mean :55.7
3rd Qu.:2674 NA 3rd Qu.:2017 NA NA NA 3rd Qu.:72.4 3rd Qu.: 98.8 3rd Qu.:65.3 3rd Qu.:81.4 3rd Qu.: 94.5 3rd Qu.:68.9 3rd Qu.:75.2 3rd Qu.:72.6 3rd Qu.:76.6 3rd Qu.:53.9 3rd Qu.: 81.6 3rd Qu.:85.1 3rd Qu.:94.1 3rd Qu.:97.2 3rd Qu.:74.3 3rd Qu.:74.6 3rd Qu.:65.1
Max. :3565 NA Max. :2022 NA NA NA Max. :86.8 Max. :100.0 Max. :83.4 Max. :97.3 Max. :100.0 Max. :94.0 Max. :95.1 Max. :99.6 Max. :88.7 Max. :99.2 Max. :100.0 Max. :99.1 Max. :99.0 Max. :99.9 Max. :97.9 Max. :96.0 Max. :96.8
NA NA NA NA NA NA NA NA’s :276 NA NA NA NA NA NA NA NA NA’s :276 NA NA NA NA NA NA

Focus on the influence of the factors over the SDG scores

After importing our our cleaned data, we looked first at the correlations between our numerical variables.

#### Correlations between variables ####

Correlation_overall <- data_question1 %>% 
      select(population:ef_regulation)
cor_matrix <- cor(Correlation_overall, use = "everything")
kable(cor_matrix)
population overallscore goal1 goal2 goal3 goal4 goal5 goal6 goal7 goal8 goal9 goal10 goal11 goal12 goal13 goal15 goal16 goal17 unemployment.rate GDPpercapita MilitaryExpenditurePercentGDP internet_usage pf_law pf_security pf_movement pf_religion pf_assembly pf_expression pf_identity ef_government ef_legal ef_money ef_trade ef_regulation
population 1.000 -0.042 -0.020 0.123 -0.005 0.073 -0.023 -0.066 -0.019 0.032 0.056 -0.102 -0.111 0.109 0.046 -0.237 -0.128 -0.150 -0.088 -0.054 0.067 -0.045 -0.127 -0.046 -0.228 -0.321 -0.205 -0.115 -0.001 -0.032 -0.026 -0.046 -0.128 -0.119
overallscore -0.042 1.000 0.890 0.676 0.943 0.873 0.685 0.905 0.901 0.728 0.835 0.562 0.886 -0.767 -0.610 0.186 0.814 0.572 0.160 0.617 -0.013 0.805 0.699 0.514 0.456 0.218 0.414 0.510 0.626 -0.213 0.785 0.624 0.686 0.548
goal1 -0.020 0.890 1.000 0.518 0.894 0.822 0.448 0.796 0.867 0.562 0.672 0.480 0.799 -0.685 -0.566 0.014 0.672 0.503 0.225 0.468 0.113 0.656 0.564 0.418 0.341 0.077 0.286 0.366 0.504 -0.085 0.600 0.521 0.612 0.458
goal2 0.123 0.676 0.518 1.000 0.640 0.580 0.487 0.634 0.575 0.575 0.617 0.290 0.548 -0.459 -0.360 0.046 0.521 0.258 0.005 0.411 -0.103 0.539 0.427 0.418 0.262 0.140 0.242 0.347 0.392 -0.156 0.505 0.454 0.455 0.292
goal3 -0.005 0.943 0.894 0.640 1.000 0.851 0.606 0.875 0.879 0.702 0.812 0.487 0.873 -0.778 -0.641 0.026 0.774 0.497 0.115 0.627 0.016 0.769 0.663 0.473 0.424 0.176 0.365 0.467 0.603 -0.151 0.737 0.649 0.701 0.520
goal4 0.073 0.873 0.822 0.580 0.851 1.000 0.674 0.781 0.822 0.620 0.678 0.315 0.832 -0.659 -0.544 -0.007 0.626 0.451 0.109 0.482 -0.026 0.628 0.563 0.384 0.401 0.194 0.348 0.417 0.597 -0.054 0.687 0.544 0.635 0.481
goal5 -0.023 0.685 0.448 0.487 0.606 0.674 1.000 0.653 0.568 0.561 0.656 0.187 0.674 -0.613 -0.528 0.187 0.538 0.464 0.015 0.539 -0.171 0.634 0.555 0.241 0.432 0.304 0.351 0.441 0.595 -0.235 0.692 0.493 0.498 0.491
goal6 -0.066 0.905 0.796 0.634 0.875 0.781 0.653 1.000 0.830 0.706 0.793 0.426 0.823 -0.774 -0.620 0.163 0.755 0.490 0.133 0.624 -0.089 0.735 0.686 0.431 0.501 0.337 0.485 0.568 0.686 -0.173 0.775 0.607 0.679 0.511
goal7 -0.019 0.901 0.867 0.575 0.879 0.822 0.568 0.830 1.000 0.563 0.687 0.382 0.841 -0.653 -0.504 0.032 0.666 0.514 0.228 0.474 0.024 0.681 0.582 0.393 0.398 0.169 0.353 0.406 0.586 -0.080 0.634 0.545 0.639 0.429
goal8 0.032 0.728 0.562 0.575 0.702 0.620 0.561 0.706 0.563 1.000 0.757 0.446 0.637 -0.709 -0.612 0.158 0.656 0.272 -0.243 0.642 -0.152 0.646 0.648 0.496 0.475 0.371 0.493 0.617 0.547 -0.177 0.729 0.526 0.599 0.443
goal9 0.056 0.835 0.672 0.617 0.812 0.678 0.656 0.793 0.687 0.757 1.000 0.517 0.723 -0.837 -0.744 0.159 0.772 0.444 0.025 0.812 -0.002 0.891 0.766 0.486 0.397 0.253 0.398 0.542 0.506 -0.321 0.829 0.604 0.611 0.549
goal10 -0.102 0.562 0.480 0.290 0.487 0.315 0.187 0.426 0.382 0.446 0.517 1.000 0.336 -0.542 -0.502 0.253 0.584 0.152 -0.076 0.473 0.039 0.489 0.468 0.539 0.128 -0.053 0.112 0.241 0.181 -0.286 0.436 0.291 0.293 0.310
goal11 -0.111 0.886 0.799 0.548 0.873 0.832 0.674 0.823 0.841 0.637 0.723 0.336 1.000 -0.720 -0.590 0.040 0.741 0.514 0.175 0.564 -0.004 0.693 0.668 0.388 0.487 0.269 0.405 0.485 0.627 -0.177 0.751 0.590 0.678 0.552
goal12 0.109 -0.767 -0.685 -0.459 -0.778 -0.659 -0.613 -0.774 -0.653 -0.709 -0.837 -0.542 -0.720 1.000 0.887 -0.236 -0.818 -0.375 -0.038 -0.849 0.049 -0.736 -0.851 -0.522 -0.505 -0.361 -0.478 -0.648 -0.544 0.301 -0.838 -0.583 -0.683 -0.572
goal13 0.046 -0.610 -0.566 -0.360 -0.641 -0.544 -0.528 -0.620 -0.504 -0.612 -0.744 -0.502 -0.590 0.887 1.000 -0.151 -0.682 -0.311 0.027 -0.796 -0.067 -0.647 -0.726 -0.432 -0.352 -0.213 -0.283 -0.480 -0.406 0.301 -0.723 -0.465 -0.530 -0.514
goal15 -0.237 0.186 0.014 0.046 0.026 -0.007 0.187 0.163 0.032 0.158 0.159 0.253 0.040 -0.236 -0.151 1.000 0.236 0.111 0.160 0.182 -0.095 0.235 0.244 0.123 0.217 0.252 0.236 0.260 0.188 -0.240 0.220 0.112 0.136 0.144
goal16 -0.128 0.814 0.672 0.521 0.774 0.626 0.538 0.755 0.666 0.656 0.772 0.584 0.741 -0.818 -0.682 0.236 1.000 0.484 0.195 0.696 0.002 0.689 0.842 0.638 0.478 0.300 0.471 0.618 0.502 -0.347 0.840 0.568 0.645 0.570
goal17 -0.150 0.572 0.503 0.258 0.497 0.451 0.464 0.490 0.514 0.272 0.444 0.152 0.514 -0.375 -0.311 0.111 0.484 1.000 0.358 0.334 0.134 0.442 0.383 0.167 0.343 0.185 0.307 0.320 0.386 -0.257 0.490 0.342 0.346 0.319
unemployment.rate -0.088 0.160 0.225 0.005 0.115 0.109 0.015 0.133 0.228 -0.243 0.025 -0.076 0.175 -0.038 0.027 0.160 0.195 0.358 1.000 -0.086 0.177 0.050 0.176 0.037 0.127 0.056 0.158 0.072 0.095 -0.183 0.098 0.046 0.121 0.123
GDPpercapita -0.054 0.617 0.468 0.411 0.627 0.482 0.539 0.624 0.474 0.642 0.812 0.473 0.564 -0.849 -0.796 0.182 0.696 0.334 -0.086 1.000 -0.068 0.719 0.745 0.445 0.397 0.317 0.396 0.557 0.406 -0.311 0.756 0.492 0.507 0.493
MilitaryExpenditurePercentGDP 0.067 -0.013 0.113 -0.103 0.016 -0.026 -0.171 -0.089 0.024 -0.152 -0.002 0.039 -0.004 0.049 -0.067 -0.095 0.002 0.134 0.177 -0.068 1.000 -0.026 -0.029 -0.103 -0.306 -0.302 -0.316 -0.262 -0.191 -0.163 -0.096 -0.079 -0.087 -0.078
internet_usage -0.045 0.805 0.656 0.539 0.769 0.628 0.634 0.735 0.681 0.646 0.891 0.489 0.693 -0.736 -0.647 0.235 0.689 0.442 0.050 0.719 -0.026 1.000 0.654 0.455 0.355 0.204 0.332 0.429 0.469 -0.255 0.712 0.581 0.553 0.566
pf_law -0.127 0.699 0.564 0.427 0.663 0.563 0.555 0.686 0.582 0.648 0.766 0.468 0.668 -0.851 -0.726 0.244 0.842 0.383 0.176 0.745 -0.029 0.654 1.000 0.575 0.594 0.476 0.567 0.710 0.498 -0.334 0.852 0.538 0.668 0.625
pf_security -0.046 0.514 0.418 0.418 0.473 0.384 0.241 0.431 0.393 0.496 0.486 0.539 0.388 -0.522 -0.432 0.123 0.638 0.167 0.037 0.445 -0.103 0.455 0.575 1.000 0.377 0.162 0.301 0.422 0.238 -0.285 0.530 0.326 0.420 0.352
pf_movement -0.228 0.456 0.341 0.262 0.424 0.401 0.432 0.501 0.398 0.475 0.397 0.128 0.487 -0.505 -0.352 0.217 0.478 0.343 0.127 0.397 -0.306 0.355 0.594 0.377 1.000 0.737 0.781 0.768 0.508 0.010 0.586 0.449 0.607 0.488
pf_religion -0.321 0.218 0.077 0.140 0.176 0.194 0.304 0.337 0.169 0.371 0.253 -0.053 0.269 -0.361 -0.213 0.252 0.300 0.185 0.056 0.317 -0.302 0.204 0.476 0.162 0.737 1.000 0.846 0.754 0.411 0.098 0.412 0.293 0.430 0.333
pf_assembly -0.205 0.414 0.286 0.242 0.365 0.348 0.351 0.485 0.353 0.493 0.398 0.112 0.405 -0.478 -0.283 0.236 0.471 0.307 0.158 0.396 -0.316 0.332 0.567 0.301 0.781 0.846 1.000 0.888 0.452 0.085 0.554 0.437 0.560 0.428
pf_expression -0.115 0.510 0.366 0.347 0.467 0.417 0.441 0.568 0.406 0.617 0.542 0.241 0.485 -0.648 -0.480 0.260 0.618 0.320 0.072 0.557 -0.262 0.429 0.710 0.422 0.768 0.754 0.888 1.000 0.472 -0.090 0.690 0.484 0.612 0.471
pf_identity -0.001 0.626 0.504 0.392 0.603 0.597 0.595 0.686 0.586 0.547 0.506 0.181 0.627 -0.544 -0.406 0.188 0.502 0.386 0.095 0.406 -0.191 0.469 0.498 0.238 0.508 0.411 0.452 0.472 1.000 -0.070 0.574 0.425 0.540 0.342
ef_government -0.032 -0.213 -0.085 -0.156 -0.151 -0.054 -0.235 -0.173 -0.080 -0.177 -0.321 -0.286 -0.177 0.301 0.301 -0.240 -0.347 -0.257 -0.183 -0.311 -0.163 -0.255 -0.334 -0.285 0.010 0.098 0.085 -0.090 -0.070 1.000 -0.259 -0.007 -0.006 -0.019
ef_legal -0.026 0.785 0.600 0.505 0.737 0.687 0.692 0.775 0.634 0.729 0.829 0.436 0.751 -0.838 -0.723 0.220 0.840 0.490 0.098 0.756 -0.096 0.712 0.852 0.530 0.586 0.412 0.554 0.690 0.574 -0.259 1.000 0.604 0.694 0.676
ef_money -0.046 0.624 0.521 0.454 0.649 0.544 0.493 0.607 0.545 0.526 0.604 0.291 0.590 -0.583 -0.465 0.112 0.568 0.342 0.046 0.492 -0.079 0.581 0.538 0.326 0.449 0.293 0.437 0.484 0.425 -0.007 0.604 1.000 0.742 0.553
ef_trade -0.128 0.686 0.612 0.455 0.701 0.635 0.498 0.679 0.639 0.599 0.611 0.293 0.678 -0.683 -0.530 0.136 0.645 0.346 0.121 0.507 -0.087 0.553 0.668 0.420 0.607 0.430 0.560 0.612 0.540 -0.006 0.694 0.742 1.000 0.628
ef_regulation -0.119 0.548 0.458 0.292 0.520 0.481 0.491 0.511 0.429 0.443 0.549 0.310 0.552 -0.572 -0.514 0.144 0.570 0.319 0.123 0.493 -0.078 0.566 0.625 0.352 0.488 0.333 0.428 0.471 0.342 -0.019 0.676 0.553 0.628 1.000

By doing so, we obtain a lot of positive and negative correlations. To help us to better understand and having a overall vision of the situation, we used the following heatmap.

#### Heatmap ####

cor_melted <- melt(cor_matrix)

ggplot(data = cor_melted, aes(Var1, Var2, fill = value)) +
  geom_tile() +
  scale_fill_gradient2(low = "blue", high = "red", mid = "white", 
                       midpoint = 0, limit = c(-1, 1), space = "Lab", 
                       name="Pearson\nCorrelation") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, vjust = 1, size = 8, hjust = 1),
        axis.text.y = element_text(size = 8)) +
  coord_fixed() +
  labs(x = '', y = '', title = 'Correlation Matrix Heatmap')

In the correlation matrix heatmap, we can notice that many goals from 1 to 11 are actually positively correlated together. On another hand, the goals 12 and 13 are have negative relationships with the majority of our variables, except between themself, whereas they are strongely correlated. In addition, we can notice another strongly correlation between personal freedom variables (pf) related to the scores given by the Human Freedom Index on movement, religion, assembly and expression.

In order to have an overview of the relationship between our independent variables and the SDG overall score, we make several graphs containing the Pearson correlation coefficient between the variable, the scatter plots describing the relationship between the variables, as well as the distribution of each variable.

#### Pearson's correlation coeff ####

panel.hist <- function(x, ...){ 
  usr <- par("usr"); on.exit(par(usr)) 
  par(usr = c(usr[1:2], 0, 1.5) ) 
  h <- hist(x, plot = FALSE) 
  breaks <- h$breaks; nB <- length(breaks) 
  y <- h$counts; y <- y/max(y) 
  rect(breaks[-nB], 0, breaks[-1], y, col = "lightgreen", ...)
}
panel.cor <- function(x, y, digits = 2, prefix = "", cex.cor, ...){ 
  usr <- par("usr"); on.exit(par(usr)) 
  par(usr = c(0, 1, 0, 1)) 
  r <- (cor(x, y)) 
  txt <- format(c(r, 0.123456789), digits = digits)[1] 
  txt <- paste0(prefix, txt) 
  if(missing(cex.cor)) cex.cor <- 0.8/strwidth(txt) 
  text(0.5, 0.5, txt, cex = cex.cor * r)
}

# Independent variables 
pairs(data_question1[,c("overallscore", "unemployment.rate", "GDPpercapita", "MilitaryExpenditurePercentGDP", "internet_usage")], upper.panel=panel.cor, diag.panel=panel.hist, main="Correlation table and distribution of various variables")

The overall SDG achievement score is highly correlated with the percentage of people using the internet (r=.79) and GDP per capita (r=.60). The unemployement rate as well as the military expenditures in percentage of GDP per capita do not seem to play a role. However, this is only for the overall score.

pairs(data_question1[,c("overallscore", "pf_law", "pf_security", "pf_movement", "pf_religion", "pf_assembly", "pf_expression", "pf_identity")], upper.panel=panel.cor, diag.panel=panel.hist, main="Correlation table and distribution of personal freedom variables")

The overall SDG achievement score is highly correlated with “personal freedom: law” (p=.69) and “personal freedom: identity” (p=.62). The other dimensions of personal freedom do not seem to have important influence. Regarding the distribution of the personal freedom variables, we notice that except for law, all have right-skewed distributions meaning that most of the countries have high scores.

pairs(data_question1[,c("overallscore", "ef_government", "ef_legal", "ef_money", "ef_trade", "ef_regulation")], upper.panel=panel.cor, diag.panel=panel.hist, main="Correlation table and distribution of economic freedom variables")

The overall SDG achievement score is highly correlated with “economical freedom: legal” (p=.77), “economical trade: legal” (p=.67) and “economical freedom: money” (p=.6), while the other dimensions of economic freedom do not seem to have important influence. Regarding the distribution of the economic freedom variables, we notice more heterogeneous distributions and scores across the various countries than for personal freedom.

#### PCA ####

# for goals
myPCA_g <- PCA(data_question1[,9:20])
summary(myPCA_g)
#> 
#> Call:
#> PCA(X = data_question1[, 9:20]) 
#> 
#> 
#> Eigenvalues
#>                        Dim.1   Dim.2   Dim.3   Dim.4   Dim.5   Dim.6
#> Variance               8.562   0.926   0.763   0.525   0.358   0.236
#> % of var.             71.352   7.715   6.362   4.379   2.984   1.966
#> Cumulative % of var.  71.352  79.067  85.429  89.808  92.792  94.758
#>                        Dim.7   Dim.8   Dim.9  Dim.10  Dim.11  Dim.12
#> Variance               0.176   0.153   0.123   0.094   0.063   0.020
#> % of var.              1.463   1.275   1.022   0.786   0.529   0.166
#> Cumulative % of var.  96.221  97.496  98.519  99.305  99.834 100.000
#> 
#> Individuals (the 10 first)
#>                  Dist    Dim.1    ctr   cos2    Dim.2    ctr   cos2
#> 1            |  4.882 | -4.671  0.102  0.915 | -0.382  0.006  0.006
#> 2            |  4.857 | -4.647  0.101  0.915 | -0.397  0.007  0.007
#> 3            |  4.778 | -4.579  0.098  0.919 | -0.420  0.008  0.008
#> 4            |  4.704 | -4.509  0.095  0.919 | -0.443  0.008  0.009
#> 5            |  4.662 | -4.467  0.093  0.918 | -0.461  0.009  0.010
#> 6            |  4.565 | -4.378  0.090  0.920 | -0.492  0.010  0.012
#> 7            |  4.500 | -4.324  0.087  0.923 | -0.493  0.011  0.012
#> 8            |  4.421 | -4.248  0.084  0.923 | -0.509  0.011  0.013
#> 9            |  3.932 | -3.784  0.067  0.926 | -0.079  0.000  0.000
#> 10           |  3.846 | -3.679  0.063  0.915 | -0.130  0.001  0.001
#>                 Dim.3    ctr   cos2  
#> 1            | -0.154  0.001  0.001 |
#> 2            | -0.095  0.000  0.000 |
#> 3            | -0.083  0.000  0.000 |
#> 4            | -0.044  0.000  0.000 |
#> 5            | -0.026  0.000  0.000 |
#> 6            | -0.018  0.000  0.000 |
#> 7            | -0.035  0.000  0.000 |
#> 8            | -0.046  0.000  0.000 |
#> 9            |  0.198  0.002  0.003 |
#> 10           |  0.391  0.008  0.010 |
#> 
#> Variables (the 10 first)
#>                 Dim.1    ctr   cos2    Dim.2    ctr   cos2    Dim.3
#> overallscore |  0.986 11.350  0.972 |  0.054  0.312  0.003 | -0.060
#> goal1        |  0.880  9.045  0.774 |  0.080  0.692  0.006 | -0.384
#> goal2        |  0.705  5.799  0.496 | -0.062  0.409  0.004 |  0.333
#> goal3        |  0.958 10.723  0.918 |  0.025  0.065  0.001 | -0.128
#> goal4        |  0.890  9.260  0.793 | -0.210  4.767  0.044 | -0.152
#> goal5        |  0.716  5.993  0.513 | -0.373 15.059  0.139 |  0.348
#> goal6        |  0.924  9.961  0.853 | -0.038  0.157  0.001 |  0.000
#> goal7        |  0.898  9.426  0.807 | -0.089  0.853  0.008 | -0.292
#> goal8        |  0.776  7.025  0.602 |  0.133  1.900  0.018 |  0.405
#> goal9        |  0.867  8.781  0.752 |  0.125  1.683  0.016 |  0.268
#>                 ctr   cos2  
#> overallscore  0.473  0.004 |
#> goal1        19.362  0.148 |
#> goal2        14.537  0.111 |
#> goal3         2.133  0.016 |
#> goal4         3.031  0.023 |
#> goal5        15.906  0.121 |
#> goal6         0.000  0.000 |
#> goal7        11.137  0.085 |
#> goal8        21.458  0.164 |
#> goal9         9.402  0.072 |
myPCA_g$eig
#>         eigenvalue percentage of variance
#> comp 1      8.5622                 71.352
#> comp 2      0.9258                  7.715
#> comp 3      0.7635                  6.362
#> comp 4      0.5255                  4.379
#> comp 5      0.3581                  2.984
#> comp 6      0.2359                  1.966
#> comp 7      0.1755                  1.463
#> comp 8      0.1530                  1.275
#> comp 9      0.1227                  1.022
#> comp 10     0.0943                  0.786
#> comp 11     0.0635                  0.529
#> comp 12     0.0199                  0.166
#>         cumulative percentage of variance
#> comp 1                               71.4
#> comp 2                               79.1
#> comp 3                               85.4
#> comp 4                               89.8
#> comp 5                               92.8
#> comp 6                               94.8
#> comp 7                               96.2
#> comp 8                               97.5
#> comp 9                               98.5
#> comp 10                              99.3
#> comp 11                              99.8
#> comp 12                             100.0

Concerning the SDG goals, we conclude that most of our variables are going along the 1st component, except the goals 10 and 15 that are rather uncorrelated with the dimension 1. In addition, as seen before, the goals 12 and 13 are negatively correlated to the other goals. With a eigenvalue bigger than 1 for the first two components, we conclude that there are only 2 dimensions to take into account, according to the Kaiser-Guttman’s rule. Nevertheless, they are explaining less than 80% of cumulated variance.

#for HFI scores
myPCA_s <- PCA(data_question1[,30:41])
summary(myPCA_s)
#> 
#> Call:
#> PCA(X = data_question1[, 30:41]) 
#> 
#> 
#> Eigenvalues
#>                        Dim.1   Dim.2   Dim.3   Dim.4   Dim.5   Dim.6
#> Variance               6.477   1.581   1.081   0.710   0.560   0.476
#> % of var.             53.979  13.171   9.010   5.920   4.666   3.966
#> Cumulative % of var.  53.979  67.150  76.160  82.080  86.746  90.713
#>                        Dim.7   Dim.8   Dim.9  Dim.10  Dim.11  Dim.12
#> Variance               0.305   0.230   0.207   0.181   0.116   0.075
#> % of var.              2.545   1.914   1.724   1.512   0.970   0.623
#> Cumulative % of var.  93.257  95.171  96.895  98.407  99.377 100.000
#> 
#> Individuals (the 10 first)
#>                   Dist    Dim.1    ctr   cos2    Dim.2    ctr   cos2
#> 1             |  5.714 | -4.642  0.133  0.660 |  0.939  0.022  0.027
#> 2             |  4.928 | -4.333  0.116  0.773 |  0.560  0.008  0.013
#> 3             |  4.964 | -4.238  0.111  0.729 |  1.063  0.029  0.046
#> 4             |  3.666 | -3.523  0.077  0.924 |  0.149  0.001  0.002
#> 5             |  3.589 | -3.355  0.070  0.874 |  0.102  0.000  0.001
#> 6             |  5.952 | -4.479  0.124  0.566 |  0.505  0.006  0.007
#> 7             |  4.722 | -3.585  0.079  0.576 | -0.592  0.009  0.016
#> 8             |  4.660 | -3.610  0.081  0.600 | -0.655  0.011  0.020
#> 9             |  4.717 | -3.680  0.084  0.608 | -0.736  0.014  0.024
#> 10            |  4.105 | -3.623  0.081  0.779 |  0.677  0.012  0.027
#>                  Dim.3    ctr   cos2  
#> 1             |  0.942  0.033  0.027 |
#> 2             |  0.749  0.021  0.023 |
#> 3             |  1.081  0.043  0.047 |
#> 4             |  0.471  0.008  0.017 |
#> 5             |  0.518  0.010  0.021 |
#> 6             | -2.619  0.254  0.194 |
#> 7             | -2.518  0.235  0.284 |
#> 8             | -2.430  0.218  0.272 |
#> 9             | -2.639  0.258  0.313 |
#> 10            | -1.023  0.039  0.062 |
#> 
#> Variables (the 10 first)
#>                  Dim.1    ctr   cos2    Dim.2    ctr   cos2    Dim.3
#> pf_law        |  0.856 11.301  0.732 | -0.311  6.109  0.097 | -0.118
#> pf_security   |  0.547  4.627  0.300 | -0.465 13.663  0.216 | -0.203
#> pf_movement   |  0.828 10.572  0.685 |  0.291  5.367  0.085 | -0.140
#> pf_religion   |  0.705  7.668  0.497 |  0.554 19.445  0.307 | -0.275
#> pf_assembly   |  0.820 10.391  0.673 |  0.444 12.492  0.197 | -0.196
#> pf_expression |  0.879 11.918  0.772 |  0.214  2.907  0.046 | -0.248
#> pf_identity   |  0.645  6.423  0.416 |  0.007  0.003  0.000 |  0.087
#> ef_government | -0.122  0.228  0.015 |  0.684 29.606  0.468 |  0.573
#> ef_legal      |  0.862 11.459  0.742 | -0.309  6.060  0.096 |  0.037
#> ef_money      |  0.692  7.401  0.479 | -0.157  1.559  0.025 |  0.487
#>                  ctr   cos2  
#> pf_law         1.277  0.014 |
#> pf_security    3.823  0.041 |
#> pf_movement    1.804  0.020 |
#> pf_religion    6.988  0.076 |
#> pf_assembly    3.561  0.038 |
#> pf_expression  5.707  0.062 |
#> pf_identity    0.692  0.007 |
#> ef_government 30.323  0.328 |
#> ef_legal       0.126  0.001 |
#> ef_money      21.925  0.237 |
myPCA_s$eig
#>         eigenvalue percentage of variance
#> comp 1      6.4775                 53.979
#> comp 2      1.5806                 13.171
#> comp 3      1.0812                  9.010
#> comp 4      0.7104                  5.920
#> comp 5      0.5599                  4.666
#> comp 6      0.4760                  3.966
#> comp 7      0.3054                  2.545
#> comp 8      0.2297                  1.914
#> comp 9      0.2068                  1.724
#> comp 10     0.1814                  1.512
#> comp 11     0.1164                  0.970
#> comp 12     0.0748                  0.623
#>         cumulative percentage of variance
#> comp 1                               54.0
#> comp 2                               67.2
#> comp 3                               76.2
#> comp 4                               82.1
#> comp 5                               86.7
#> comp 6                               90.7
#> comp 7                               93.3
#> comp 8                               95.2
#> comp 9                               96.9
#> comp 10                              98.4
#> comp 11                              99.4
#> comp 12                             100.0

Now concerning the Human Freedom Index scores, most of the variables are positively correlated to the dimension 1, slightly less for the PF religion and security, and finaly the EF government variable is uncorrelated to the dimension 1. With a eigenvalue bigger than 1 for the three first components, we conclude that there are 3 dimensions to take into account. Nevertheless, again, they are explaining less than 80% of cumulated variance.

#### Kmean clustering ####

data1_scaled <- scale(Correlation_overall)
row.names(data1_scaled) <- data_question1[,1]
fviz_nbclust(data1_scaled, kmeans, method="wss")
kmean <- kmeans(data1_scaled, 7, nstart = 25)
print(kmean)
#> K-means clustering with 7 clusters of sizes 649, 328, 415, 417, 362, 286, 42
#> 
#> Cluster means:
#>   population overallscore  goal1    goal2   goal3  goal4   goal5
#> 1    -0.1175     -1.36318 -1.449 -0.81472 -1.3936 -1.385 -0.8789
#> 2    -0.0541      0.17641  0.544  0.00762  0.2521  0.149 -0.3879
#> 3    -0.2228      0.90857  0.782  0.66143  0.8405  0.795  0.4841
#> 4    -0.0441     -0.00632  0.188  0.17283  0.1959  0.371  0.1977
#> 5    -0.0600      1.23573  0.801  0.88135  1.1750  0.849  1.1963
#> 6    -0.2757      0.07437  0.277 -0.56992 -0.1056  0.133 -0.0352
#> 7     7.2721     -0.38531 -0.247  0.56278 -0.0921  0.469 -0.2078
#>     goal6  goal7   goal8  goal9 goal10 goal11 goal12  goal13  goal15
#> 1 -1.2223 -1.384 -0.8171 -0.981 -0.415 -1.345  0.957  0.7707  0.0747
#> 2 -0.1950  0.295 -0.3245 -0.115  0.383  0.195  0.279 -0.0591 -0.5520
#> 3  0.8673  0.800  0.7735  0.695  0.636  0.771 -0.716 -0.4075  0.6050
#> 4  0.1533  0.275 -0.0246 -0.394 -0.955  0.237  0.380  0.5083 -0.6663
#> 5  1.3303  0.855  1.4579  1.716  1.020  1.061 -1.788 -1.6815  0.4901
#> 6 -0.0731  0.183 -0.7134 -0.268 -0.202  0.131  0.150  0.2447  0.1412
#> 7 -0.6498 -0.172  0.0534  0.128 -0.800 -0.754  0.725  0.3586 -1.3909
#>   goal16   goal17 unemployment.rate GDPpercapita
#> 1 -1.013 -0.88702           -0.4506       -0.614
#> 2 -0.101  0.25031           -0.0371       -0.316
#> 3  0.795 -0.00349            0.2777        0.252
#> 4 -0.517 -0.07079           -0.3422       -0.435
#> 5  1.524  0.85550           -0.3224        2.003
#> 6  0.187  0.91913            1.6081       -0.438
#> 7 -0.684 -1.14336           -0.2663       -0.497
#>   MilitaryExpenditurePercentGDP internet_usage pf_law pf_security
#> 1                        -0.131        -0.9411 -0.832     -0.4806
#> 2                         0.879        -0.0108 -0.490     -0.0541
#> 3                         0.108         0.6929  0.802      0.7241
#> 4                        -0.517        -0.2850 -0.543     -0.7438
#> 5                        -0.314         1.3701  1.602      0.9262
#> 6                         0.226        -0.1110  0.141      0.0120
#> 7                         0.403        -0.4433 -0.626      0.0151
#>   pf_movement pf_religion pf_assembly pf_expression pf_identity
#> 1      -0.605      -0.165      -0.490       -0.5657      -0.932
#> 2      -1.148      -1.736      -1.515       -1.2681      -0.653
#> 3       0.658       0.546       0.703        0.7639       0.750
#> 4       0.316       0.427       0.325        0.0394       0.304
#> 5       0.908       0.748       0.918        1.3118       0.879
#> 6       0.326       0.309       0.397        0.0165       0.197
#> 7      -1.378      -2.071      -1.379       -0.7129       0.156
#>   ef_government ef_legal ef_money ef_trade ef_regulation
#> 1        0.0485  -0.9672  -0.9082  -1.0115        -0.727
#> 2       -0.1659  -0.4117  -0.2798  -0.4079        -0.274
#> 3       -0.2337   0.6501   0.7269   0.8652         0.362
#> 4        0.9587  -0.3821   0.1523   0.1605        -0.238
#> 5       -0.7281   1.7424   0.9840   1.0330         1.105
#> 6        0.0255   0.0860  -0.0965   0.0753         0.495
#> 7       -0.5607  -0.0729  -0.2994  -0.7427        -0.731
#> 
#> Clustering vector:
#>    1    2    3    4    5    6    7    8    9   10   11   12   13 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#>   14   15   16   17   18   19   20   21   22   23   24   25   26 
#>    1    1    1    1    1    1    1    1    6    6    6    6    6 
#>   27   28   29   30   31   32   33   34   35   36   37   38   39 
#>    6    6    6    6    6    6    6    6    6    6    6    6    6 
#>   40   41   42   43   44   45   46   47   48   49   50   51   52 
#>    3    3    6    2    2    2    2    2    2    2    2    2    2 
#>   53   54   55   56   57   58   59   60   61   62   63   64   65 
#>    2    2    2    2    2    2    2    2    2    2    2    4    4 
#>   66   67   68   69   70   71   72   73   74   75   76   77   78 
#>    4    4    4    4    4    4    4    4    4    4    4    4    4 
#>   79   80   81   82   83   84   85   86   87   88   89   90   91 
#>    4    4    3    3    4    4    6    6    6    6    6    6    6 
#>   92   93   94   95   96   97   98   99  100  101  102  103  104 
#>    6    6    2    6    6    6    6    6    6    6    6    6    3 
#>  105  106  107  108  109  110  111  112  113  114  115  116  117 
#>    3    5    5    5    5    5    5    5    5    5    5    5    5 
#>  118  119  120  121  122  123  124  125  126  127  128  129  130 
#>    5    5    5    5    5    5    5    5    5    5    5    5    5 
#>  131  132  133  134  135  136  137  138  139  140  141  142  143 
#>    5    5    5    5    5    5    5    5    5    5    5    5    5 
#>  144  145  146  147  148  149  150  151  152  153  154  155  156 
#>    5    5    5    5    2    2    2    2    2    2    2    2    2 
#>  157  158  159  160  161  162  163  164  165  166  167  168  169 
#>    2    2    2    2    2    2    2    2    2    2    2    2    1 
#>  170  171  172  173  174  175  176  177  178  179  180  181  182 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#>  183  184  185  186  187  188  189  190  191  192  193  194  195 
#>    1    1    1    1    1    1    1    5    3    5    5    5    5 
#>  196  197  198  199  200  201  202  203  204  205  206  207  208 
#>    5    5    5    5    5    5    5    5    5    5    5    5    5 
#>  209  210  211  212  213  214  215  216  217  218  219  220  221 
#>    5    5    1    1    1    1    1    1    1    1    1    1    1 
#>  222  223  224  225  226  227  228  229  230  231  232  233  234 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#>  235  236  237  238  239  240  241  242  243  244  245  246  247 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#>  248  249  250  251  252  253  254  255  256  257  258  259  260 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#>  261  262  263  264  265  266  267  268  269  270  271  272  273 
#>    1    1    1    1    1    1    1    1    1    1    2    2    2 
#>  274  275  276  277  278  279  280  281  282  283  284  285  286 
#>    6    6    6    6    6    6    3    3    3    3    3    3    3 
#>  287  288  289  290  291  292  293  294  295  296  297  298  299 
#>    3    3    3    3    3    3    3    3    6    6    6    6    6 
#>  300  301  302  303  304  305  306  307  308  309  310  311  312 
#>    6    6    6    6    6    6    6    6    6    6    6    6    6 
#>  313  314  315  316  317  318  319  320  321  322  323  324  325 
#>    6    6    6    4    4    4    4    4    4    4    4    4    4 
#>  326  327  328  329  330  331  332  333  334  335  336  337  338 
#>    4    4    4    4    4    4    4    4    4    4    4    4    4 
#>  339  340  341  342  343  344  345  346  347  348  349  350  351 
#>    4    4    4    4    4    4    4    4    4    4    4    4    4 
#>  352  353  354  355  356  357  358  359  360  361  362  363  364 
#>    4    4    4    4    4    4    6    6    6    6    6    6    6 
#>  365  366  367  368  369  370  371  372  373  374  375  376  377 
#>    6    6    6    6    6    6    6    6    6    6    6    6    6 
#>  378  379  380  381  382  383  384  385  386  387  388  389  390 
#>    6    1    1    1    1    1    1    1    1    1    1    1    1 
#>  391  392  393  394  395  396  397  398  399  400  401  402  403 
#>    1    1    1    1    1    1    1    1    1    5    5    5    5 
#>  404  405  406  407  408  409  410  411  412  413  414  415  416 
#>    5    5    5    5    5    5    5    5    5    5    5    5    5 
#>  417  418  419  420  421  422  423  424  425  426  427  428  429 
#>    5    5    5    5    5    5    5    5    5    5    5    5    5 
#>  430  431  432  433  434  435  436  437  438  439  440  441  442 
#>    5    5    5    5    5    5    5    5    5    5    5    5    3 
#>  443  444  445  446  447  448  449  450  451  452  453  454  455 
#>    3    3    3    3    3    3    3    3    3    3    3    3    3 
#>  456  457  458  459  460  461  462  463  464  465  466  467  468 
#>    3    3    3    3    3    3    3    7    7    7    7    7    7 
#>  469  470  471  472  473  474  475  476  477  478  479  480  481 
#>    7    7    7    7    7    7    7    7    7    7    7    7    7 
#>  482  483  484  485  486  487  488  489  490  491  492  493  494 
#>    7    7    1    1    1    1    1    1    1    1    1    1    1 
#>  495  496  497  498  499  500  501  502  503  504  505  506  507 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#>  508  509  510  511  512  513  514  515  516  517  518  519  520 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#>  521  522  523  524  525  526  527  528  529  530  531  532  533 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#>  534  535  536  537  538  539  540  541  542  543  544  545  546 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#>  547  548  549  550  551  552  553  554  555  556  557  558  559 
#>    4    4    4    4    4    4    4    4    4    4    4    4    4 
#>  560  561  562  563  564  565  566  567  568  569  570  571  572 
#>    4    4    4    4    4    4    4    4    3    3    3    3    3 
#>  573  574  575  576  577  578  579  580  581  582  583  584  585 
#>    3    3    3    3    3    3    3    3    3    3    3    3    3 
#>  586  587  588  589  590  591  592  593  594  595  596  597  598 
#>    3    3    3    3    3    3    3    3    3    3    3    3    3 
#>  599  600  601  602  603  604  605  606  607  608  609  610  611 
#>    3    3    3    3    3    3    3    3    5    5    3    5    5 
#>  612  613  614  615  616  617  618  619  620  621  622  623  624 
#>    5    5    5    5    5    5    5    5    5    5    5    5    5 
#>  625  626  627  628  629  630  631  632  633  634  635  636  637 
#>    5    5    5    5    5    5    5    5    5    5    5    5    5 
#>  638  639  640  641  642  643  644  645  646  647  648  649  650 
#>    5    5    5    5    5    5    5    5    5    5    5    5    5 
#>  651  652  653  654  655  656  657  658  659  660  661  662  663 
#>    5    4    4    4    4    4    4    4    4    4    4    4    4 
#>  664  665  666  667  668  669  670  671  672  673  674  675  676 
#>    4    4    4    4    4    4    4    4    4    2    2    2    2 
#>  677  678  679  680  681  682  683  684  685  686  687  688  689 
#>    2    2    2    2    2    2    2    2    2    2    2    2    2 
#>  690  691  692  693  694  695  696  697  698  699  700  701  702 
#>    2    2    2    2    4    4    4    4    4    4    4    4    4 
#>  703  704  705  706  707  708  709  710  711  712  713  714  715 
#>    4    4    4    4    4    4    4    4    4    4    4    4    2 
#>  716  717  718  719  720  721  722  723  724  725  726  727  728 
#>    2    2    2    2    2    2    2    2    2    2    2    2    2 
#>  729  730  731  732  733  734  735  736  737  738  739  740  741 
#>    2    2    2    2    2    2    2    3    3    3    3    3    3 
#>  742  743  744  745  746  747  748  749  750  751  752  753  754 
#>    3    3    3    3    3    3    3    3    3    3    3    3    3 
#>  755  756  757  758  759  760  761  762  763  764  765  766  767 
#>    3    3    3    3    3    3    3    3    3    3    3    3    3 
#>  768  769  770  771  772  773  774  775  776  777  778  779  780 
#>    3    3    3    5    5    5    5    5    5    5    1    1    1 
#>  781  782  783  784  785  786  787  788  789  790  791  792  793 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#>  794  795  796  797  798  799  800  801  802  803  804  805  806 
#>    1    1    1    1    1    5    5    5    5    5    5    5    5 
#>  807  808  809  810  811  812  813  814  815  816  817  818  819 
#>    5    5    5    5    5    5    5    5    5    5    5    5    5 
#>  820  821  822  823  824  825  826  827  828  829  830  831  832 
#>    6    6    6    6    6    6    6    2    2    2    2    2    2 
#>  833  834  835  836  837  838  839  840  841  842  843  844  845 
#>    2    6    6    6    6    6    6    6    3    3    3    3    5 
#>  846  847  848  849  850  851  852  853  854  855  856  857  858 
#>    5    5    5    5    5    5    5    5    5    5    5    5    5 
#>  859  860  861  862  863  864  865  866  867  868  869  870  871 
#>    5    5    5    1    1    1    1    1    1    1    1    6    6 
#>  872  873  874  875  876  877  878  879  880  881  882  883  884 
#>    6    6    6    6    6    6    6    6    6    6    6    5    5 
#>  885  886  887  888  889  890  891  892  893  894  895  896  897 
#>    5    5    5    5    5    5    5    5    5    5    5    5    5 
#>  898  899  900  901  902  903  904  905  906  907  908  909  910 
#>    5    5    5    5    5    5    4    4    4    4    6    6    6 
#>  911  912  913  914  915  916  917  918  919  920  921  922  923 
#>    6    6    6    6    6    6    6    6    6    6    6    3    3 
#>  924  925  926  927  928  929  930  931  932  933  934  935  936 
#>    3    1    1    1    1    1    1    1    4    4    4    4    4 
#>  937  938  939  940  941  942  943  944  945  946  947  948  949 
#>    4    4    4    4    4    4    4    4    4    3    3    3    3 
#>  950  951  952  953  954  955  956  957  958  959  960  961  962 
#>    3    3    3    3    3    3    3    3    3    3    3    3    3 
#>  963  964  965  966  967  968  969  970  971  972  973  974  975 
#>    3    3    3    3    4    4    4    4    4    4    4    4    4 
#>  976  977  978  979  980  981  982  983  984  985  986  987  988 
#>    4    4    4    4    4    4    4    4    4    4    4    4    4 
#>  989  990  991  992  993  994  995  996  997  998  999 1000 1001 
#>    4    4    4    4    4    4    4    4    4    4    4    4    4 
#> 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 
#>    4    4    4    4    4    4    4    3    3    3    3    3    3 
#> 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 
#>    3    3    3    3    3    3    3    3    3    3    3    3    3 
#> 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 
#>    3    3    3    3    3    3    3    3    3    3    3    3    3 
#> 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 
#>    3    3    3    3    3    3    3    3    3    3    4    4    4 
#> 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 
#>    4    4    4    4    4    4    4    4    4    4    4    4    4 
#> 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 
#>    4    4    4    4    2    7    7    7    7    7    7    7    7 
#> 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 
#>    7    7    7    7    7    7    7    7    7    7    7    7    7 
#> 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 
#>    5    5    5    5    5    5    5    5    5    5    5    5    5 
#> 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 
#>    5    5    5    5    5    5    5    5    2    2    2    2    2 
#> 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 
#>    2    2    2    2    2    2    2    2    2    2    2    2    2 
#> 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 
#>    2    2    2    3    3    3    3    3    3    3    3    3    3 
#> 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 
#>    3    3    3    3    3    3    3    3    3    3    3    3    3 
#> 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 
#>    3    3    3    3    3    3    3    3    3    3    3    3    3 
#> 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 
#>    3    3    3    3    3    3    4    4    4    4    4    4    4 
#> 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 
#>    4    4    4    4    4    4    4    4    4    4    4    4    4 
#> 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 
#>    4    2    2    2    2    2    2    2    2    2    2    2    2 
#> 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 
#>    2    2    2    2    2    2    2    2    2    5    3    5    5 
#> 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 
#>    5    5    5    5    5    5    5    5    5    5    5    5    5 
#> 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 
#>    5    5    5    5    4    2    2    2    2    2    2    2    2 
#> 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 
#>    2    2    2    2    2    2    2    2    2    2    2    2    1 
#> 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#> 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 
#>    4    4    1    4    4    4    4    2    2    2    2    2    2 
#> 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 
#>    2    2    2    2    2    2    2    2    2    2    2    2    4 
#> 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 
#>    2    2    3    3    3    3    3    3    3    3    3    3    3 
#> 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 
#>    3    3    3    3    3    3    3    3    3    3    2    2    2 
#> 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 
#>    4    2    2    2    2    2    2    2    2    2    2    2    4 
#> 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 
#>    4    4    4    4    4    1    1    1    1    1    1    1    1 
#> 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 
#>    1    1    1    1    1    6    6    6    6    6    6    6    6 
#> 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 
#>    3    3    3    3    3    3    3    3    3    3    3    3    3 
#> 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 
#>    3    3    3    3    3    3    3    3    5    5    5    5    5 
#> 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 
#>    5    5    5    5    5    5    5    5    5    5    5    5    5 
#> 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 
#>    5    5    5    3    3    3    3    3    3    3    3    3    3 
#> 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 
#>    3    3    3    3    3    3    3    3    3    3    3    2    2 
#> 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 
#>    2    2    2    2    2    2    2    2    2    2    2    2    2 
#> 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 
#>    2    2    2    2    2    2    4    4    4    4    6    6    6 
#> 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 
#>    6    6    6    6    6    6    6    6    6    3    3    3    3 
#> 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 
#>    3    1    1    1    1    1    1    1    1    1    1    1    1 
#> 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 
#>    1    1    1    1    1    1    1    1    1    4    4    4    4 
#> 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 
#>    4    4    4    4    4    4    4    4    4    4    4    4    4 
#> 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 
#>    4    4    4    4    6    6    6    6    6    6    6    6    6 
#> 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 
#>    6    6    6    6    6    6    6    6    6    6    6    6    1 
#> 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#> 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#> 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 
#>    1    1    1    1    1    1    1    1    2    2    2    2    2 
#> 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 
#>    2    2    6    6    6    6    6    6    6    6    6    6    6 
#> 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 
#>    6    6    6    6    6    6    6    6    6    6    6    6    6 
#> 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 
#>    6    6    6    6    6    6    6    6    6    6    6    6    6 
#> 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 
#>    6    6    6    6    6    1    1    1    1    1    1    1    1 
#> 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#> 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#> 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 
#>    1    1    1    1    1    1    1    1    4    4    4    4    4 
#> 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 
#>    4    4    4    4    4    4    4    4    4    4    4    4    4 
#> 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 
#>    4    4    4    1    1    1    1    1    1    1    1    1    1 
#> 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 
#>    1    1    1    1    1    1    1    1    1    1    1    2    2 
#> 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 
#>    2    2    2    2    2    2    2    2    2    2    2    2    2 
#> 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 
#>    2    2    2    4    4    2    6    6    6    6    6    6    6 
#> 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 
#>    6    6    6    6    6    6    6    6    6    6    6    6    6 
#> 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 
#>    6    1    1    1    1    1    1    1    1    1    1    1    1 
#> 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#> 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#> 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 
#>    1    1    1    1    4    4    4    4    4    4    4    4    4 
#> 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 
#>    4    4    4    4    4    4    4    4    4    2    2    2    5 
#> 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 
#>    5    5    5    5    5    5    5    5    5    5    5    5    5 
#> 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 
#>    5    5    5    5    5    5    5    5    5    5    5    5    5 
#> 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 
#>    5    5    5    5    5    5    5    5    5    5    5    5    5 
#> 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 
#>    5    5    1    1    1    1    1    1    1    1    1    1    1 
#> 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 
#>    1    1    1    4    4    4    6    6    4    6    1    1    1 
#> 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#> 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 
#>    1    1    1    1    1    4    4    4    4    4    4    4    4 
#> 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 
#>    4    4    4    4    4    4    4    4    4    4    4    4    4 
#> 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 
#>    4    4    4    4    4    4    4    4    4    4    4    4    4 
#> 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 
#>    4    4    4    4    4    4    4    4    1    1    1    1    1 
#> 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#> 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 
#>    1    1    1    3    3    3    3    3    3    3    3    3    3 
#> 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 
#>    3    3    3    3    3    3    3    3    3    3    3    3    3 
#> 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 
#>    3    3    3    3    3    3    3    3    3    3    3    3    3 
#> 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 
#>    3    3    3    3    3    3    4    4    4    4    4    4    4 
#> 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 
#>    4    4    4    4    4    4    4    4    4    4    4    4    4 
#> 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 
#>    4    4    4    4    4    4    4    4    3    3    3    3    3 
#> 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 
#>    3    3    3    3    3    3    3    3    3    2    2    2    2 
#> 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 
#>    2    2    2    2    2    2    2    2    2    2    2    2    2 
#> 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 
#>    2    2    2    2    1    1    1    1    1    1    1    1    1 
#> 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 
#>    1    1    1    1    1    1    2    2    2    2    2    2    1 
#> 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#> 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 
#>    1    1    1    1    1    4    1    1    1    1    1    1    1 
#> 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#> 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 
#>    1    1    4    4    4    4    4    4    4    4    4    4    4 
#> 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 
#>    4    4    4    4    4    4    4    4    4    4    6    6    6 
#> 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 
#>    6    6    6    6    6    6    6    6    6    6    6    6    6 
#> 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 
#>    6    3    3    3    3    3    3    3    3    3    3    3    3 
#> 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 
#>    3    3    3    3    3    3    3    3    3    3    3    3    3 
#> 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 
#>    3    3    3    3    3    3    3    3    3    3    3    3    3 
#> 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 
#>    3    3    3    3    3    5    5    3    5    5    5    5    5 
#> 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 
#>    5    5    5    5    5    5    5    5    5    5    5    5    5 
#> 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 
#>    5    5    5    1    1    1    1    1    1    1    1    1    1 
#> 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#> 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#> 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 
#>    1    1    1    1    1    1    4    4    4    4    4    4    4 
#> 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 
#>    4    4    4    4    4    4    4    2    2    2    2    2    4 
#> 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 
#>    2    2    2    2    2    2    2    2    2    2    2    2    6 
#> 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 
#>    6    6    6    6    6    6    6    6    2    2    2    2    2 
#> 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 
#>    2    2    2    2    2    6    2    2    2    2    2    2    2 
#> 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 
#>    2    2    2    2    1    1    1    1    1    1    1    1    1 
#> 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#> 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#> 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 
#>    1    1    1    1    1    1    1    6    6    6    6    6    3 
#> 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 
#>    3    3    3    3    3    3    3    3    3    3    3    3    3 
#> 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 
#>    3    3    5    5    5    5    5    5    5    5    5    5    5 
#> 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 
#>    5    5    5    5    5    5    5    5    5    5    2    2    2 
#> 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 
#>    2    2    2    2    2    2    2    2    2    2    2    2    2 
#> 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 
#>    2    2    2    2    2    6    6    6    6    6    6    6    6 
#> 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 
#>    6    6    6    6    6    6    6    6    6    6    6    6    6 
#> 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#> 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#> 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 
#>    1    1    1    1    1    1    1    1    1    1    1    1    1 
#> 2497 2498 2499 
#>    1    1    1 
#> 
#> Within cluster sum of squares by cluster:
#> [1] 10371  5910  4023  4976  2844  4594   750
#>  (between_SS / total_SS =  60.6 %)
#> 
#> Available components:
#> 
#> [1] "cluster"      "centers"      "totss"        "withinss"    
#> [5] "tot.withinss" "betweenss"    "size"         "iter"        
#> [9] "ifault"
fviz_cluster(kmean, data=data1_scaled, repel=TRUE, depth =NULL, ellipse.type = "norm")

Due to the large number of data, the visualization of the clusters using the kmean method is not really relevant. In addition, by clustering our data, we are trying to get group that differ from eachother but with little variation of the observations within the same cluster. Here, only 60.6% of the variance is explained by the variation between clusters. This is not enough.

Focus on the evolution of SDG scores over time

First, we look at the evolution of SDG achievement overall score over time for the whole world, by continent and by region.

data1 <- data_question2 %>% group_by(year) %>%
  mutate(mean_overall_score_by_year=mean(overallscore))

ggplot(data1) +
  geom_line(mapping=aes(x=year, y=mean_overall_score_by_year), color="blue", lwd=1) +
  scale_y_continuous(limits = c(0, 100))  +
  labs(title = "Evolution of the mean overall SDG achievement score across the world",
       y = "Mean Overall SDG Score",
       x = "Year"
       )

The general evolution of SDG scores around the world is increasing over the years.

data2 <- data_question2 %>% group_by(year, continent) %>%
  mutate(mean_overall_score_by_year=mean(overallscore))

ggplot(data2) +
  geom_line(mapping=aes(x=year, y=mean_overall_score_by_year, color=continent), lwd=1) +
  scale_y_continuous(limits = c(0, 100)) +
  labs(title = "Evolution of the mean overall SDG achievement score by continent",
       y = "Mean Overall SDG Score",
       x = "Year"
       )

Looking at the continents, we see that Europe is above the others, while Africa is below, but in general, all have increasing overall scores.

data3 <- data_question2 %>% group_by(year, region) %>%
  mutate(mean_overall_score_by_year=mean(overallscore))

ggplot(data3) +
  geom_line(mapping=aes(x=year, y=mean_overall_score_by_year, color=region), lwd=1) +
  scale_y_continuous(limits = c(0, 100)) +
  labs(title = "Evolution of the mean overall SDG achievement score by region",
       y = "Mean Overall SDG Score",
       x = "Year"
       )

This view that groups the countries by region gives us precision about the previous information. Indeed, it is Western Europe that is particularly above and Sub-Saharan Africa that is clearly below.

Second, we look at the evolution of SDG achievement scores(16) over time for the whole world, by continent and by region.

data4 <- data_question2 %>%
  group_by(year) %>%
  summarise(across(starts_with("goal"), mean, na.rm=TRUE)) %>%
  pivot_longer(cols = starts_with("goal"), names_to = "goal", values_to = "mean_value")

color_palette <- c("red", "blue", "green", "orange", "purple", "pink", "brown", "gray", "cyan", "magenta", "yellow", "darkgreen", "darkblue", "darkred", "darkorange", "darkcyan")

ggplot(data = data4) +
  geom_line(mapping = aes(x = year, y = mean_value, color = goal), size = 0.7) +
  scale_color_manual(values = color_palette) +
  scale_y_continuous(limits = c(0, 100)) +
  labs(title = "Evolution of the mean SDG achievement scores across the world",
       y = "Mean SDG Scores",
       x = "Year"
       ) +
  guides(
    color = guide_legend(
      ncol = 2,        # Number of columns
      title.position = "top",  # Position of the legend title
      title.hjust = 0.5        # Horizontal justification of the legend title
    )
  )

Here, by looking at the SDGs individually, we notice that all SDGs except from goal 9 (industry innovation and infrastructure) are close to one another in terms of level and growth. Goal 9 starts far below the others in 2000 and growths faster until almost exceeding 50%.

ggplot(data = data4) +
  geom_line(mapping = aes(x = year, y = mean_value), size = 0.7) +
  scale_color_manual(values = color_palette) +
  scale_y_continuous(limits = c(0, 100)) +
  labs(title = "Evolution of the mean SDG achievement scores across the world",
       y = "Mean SDG Scores",
       x = "Year"
       ) +
  facet_wrap(~ goal, nrow = 4)

In contrast to the aspect discussed in the precedent graph, this graph shows us the same information in a different way and it pops out that some goals did not increase their scores much in the last two decades, for example goal 13 (climate action) and goal 12 (responsible consumption and production).

data5 <- data_question2 %>%
  group_by(year, continent) %>%
  summarise(across(starts_with("goal"), mean, na.rm=TRUE)) %>%
  pivot_longer(cols = starts_with("goal"), names_to = "goal", values_to = "mean_value")

color_palette <- c("red", "blue", "green", "orange", "purple", "pink", "brown", "gray", "cyan", "magenta", "yellow", "darkgreen", "darkblue", "black", "darkorange", "darkcyan")

ggplot(data = data5) +
  geom_line(mapping = aes(x = year, y = mean_value, color=continent), size = 0.7) +
  scale_color_manual(values = color_palette) +
  scale_y_continuous(limits = c(0, 100)) +
  labs(title = "Evolution of the mean SDG achievement scores by continent",
       y = "Mean SDG Scores",
       x = "Years from 2000 to 2022"
       ) +
  facet_wrap(~ goal, nrow = 4)+
  scale_x_continuous(breaks = NULL)

Now, comparing the SDG scores by continent, we observe that most of the time, Europe is at the top of the graph and Africa at the bottom, exept for goals 12 and 13 that are linked to ecology. Some other information stand out:

  • Americas are far behind the other parts of the world regarding goal 10: reduced inequalities.

  • Africa is far behind the other continents (even if becoming better) for goals 1, 3, 4 and 7.

  • Goal 9 (industry, innovation and infrastructure) show exponential growth for almost all continents.

Third we create an interactive map of the world to be able to navigate from year 2000 to 2022, seeing the level of achievement of the SDGs (overall score) for each country. To open it in your browser, use this R file: interactive_map_1. Here is only a non-interactive world map of the overall SDGs achievement scores, not taking into account the evolution over the years.

library(rnaturalearth)
library(tidyverse)
library(sf)
# Load world map data
world <- ne_countries(scale = "medium", returnclass = "sf")

# Merge data with the world map data
data0 <- merge(world, data_question2, by.x = "iso_a3", by.y = "code", all.x = TRUE)

data0 %>%
  sf::st_transform(crs = "+proj=robin") %>%
  ggplot() +
  geom_sf(color = "lightgrey") +
  geom_sf(aes(fill = overallscore), color = NA) +
  scale_fill_gradientn(
    colors = c("darkred", "orange", "yellow", "darkgreen"),
    values = scales::rescale(c(0, 0.25, 0.5, 1)),
    name = "Overall Score",
    na.value = NA
  ) +
  labs(title = "Mean overall SDG achievement score by country")+
  coord_sf(datum = NA) +
  theme_minimal()

Focus on the influence of events over the SDG scores

In order to have an overview of the relationship between the different events variables and the SDG overall score, we make several graphs containing the Pearson correlation coefficient between the variable, the scatter plots describing the relationship between the variables, as well as the distribution of each variable.

pairs(data_question3_2[,c("overallscore", "cases_per_million", "deaths_per_million", "stringency")], upper.panel=panel.cor, diag.panel=panel.hist, main="Correlation table and distribution of COVID variables")

The different variables used to materialize the impact of COVID19 do not seem to have important influence on the overall score, but we will further explore for the different SDGs, since we believe that COVID19 had a specific influence on some SDGs, for instance “good health and well-being” or “decent work and economic growth”.

pairs(data_question3_3[,c("overallscore", "ongoing", "sum_deaths", "pop_affected", "area_affected", "maxintensity")], upper.panel=panel.cor, diag.panel=panel.hist, main="Correlation table and distribution of conflicts variables")

The different variables used to materialize the impact of conflicts do not seem to have important influence on the overall score, but we will further explore for the different SDGs, since we believe that conflicts have a specific influence on some SDGs.

To explore our data on events such as disasters, covid-19 and conflicts we have to first see which countries are the most touched by these. To do so, we made time-series analysis on this three events each time depending on different variables.

# Converted 'year' column to date format
Q3.1$year <- as.Date(as.character(Q3.1$year), format = "%Y")
Q3.2$year <- as.Date(as.character(Q3.2$year), format = "%Y")
Q3.3$year <- as.Date(as.character(Q3.3$year), format = "%Y")

These is our time-analysis concerning the COVID-19 cases per million by region between end 2018 and 2022.

covid_filtered <- Q3.2[Q3.2$year >= as.Date("2018-12-12"), ]

ggplot(data = covid_filtered, aes(x = year, y = cases_per_million, group = region, color = region)) +
  geom_smooth(method = "loess",  se = FALSE, span = 0.8, size = 0.5) + 
  labs(title = "Trend of COVID-19 Cases per Million Over Time",
       x = "Year", y = "Cases per Million") +
  facet_wrap(~ region, nrow = 2) +
  theme_minimal() +
  theme(legend.position = "bottom") +
  guides(color = guide_legend(nrow = 4))

These is our time-analysis concerning the COVID-19 deaths per million per region between end 2018 and 2022

ggplot(data = covid_filtered, aes(x = year, y = deaths_per_million, group = region, color = region)) +
  geom_smooth(method = "loess",  se = FALSE, span = 0.8, size = 0.5) + 
  labs(title = "Trend of COVID-19 Deaths per Million Over Time", x = "Year", y = "Deaths per Million") +
  facet_wrap(~ region, nrow = 2) +
  theme_minimal() +
  theme(legend.position = "bottom") +
  guides(color = guide_legend(nrow = 4))

These is our time-analysis concerning the COVID-19 stringency per region between end 2018 and 2022

ggplot(data = covid_filtered, aes(x = year, y = stringency, group = region, color = region)) +
  geom_smooth(method = "loess",  se = FALSE, span = 0.7, size = 0.5) + 
  labs(title = "Trend of COVID-19 Stringency Over Time", x = "Year", y = "Stringency") +
  facet_wrap(~ region, nrow = 2) +
  theme_minimal() +
  theme(legend.position = "bottom") +
  guides(color = guide_legend(nrow = 4))

These is our time-analysis concerning climatic disasters with total affected per region

Q3.1[is.na(Q3.1)] <- 0
ggplot(data = Q3.1, aes(x = year, y = total_affected, group = region, color = region)) +
  geom_smooth(method = "loess",  se = FALSE, span = 0.7, size = 0.5) + 
  labs(title = "Trend of Total Affected from Climatic Disasters Over Time", x = "Year", y = "Total Affected") +
  facet_wrap(~ region, nrow = 2) +
  theme_minimal() +
  theme(legend.position = "bottom") +
  guides(color = guide_legend(nrow = 4))

These is our time-analysis concerning conflicts deaths per region between 2000 and 2016

conflicts_filtered <- Q3.3[Q3.3$year >= as.Date("2000-01-01") & Q3.3$year <= as.Date("2016-12-31"), ]

ggplot(data = conflicts_filtered, aes(x = year, y = sum_deaths, group = region, color = region)) +
  geom_smooth(method = "loess", se = FALSE, span = 0.3, size = 0.5) +  # Using loess smoothing method
  labs(title = "Trend of Deaths by Conflicts Over Time", x = "Year", y = "Sum Deaths") +
  facet_wrap(~ region, nrow = 2) +
  theme_minimal() +
  theme(legend.position = "bottom") +
  guides(color = guide_legend(nrow = 4))

We can see that the regions’ the most affected by the conflicts are : Middle east and north Africa, Sub-Saharan Africa, South Asia, then less America & the Caribbean and Eastern Europe

These is our time-analysis concerning conflicts affected population per region between 2000 and 2016

ggplot(data = conflicts_filtered, aes(x = year, y = pop_affected, group = region, color = region)) +
  geom_smooth(method = "loess", se = FALSE, span = 0.3, size = 0.5) +  # Using loess smoothing method
  labs(title = "Trend of Population Affected by Conflicts Over Time", x = "Year", y = "pop_affected") +
  facet_wrap(~ region, nrow = 2) +
  theme_minimal() +
  theme(legend.position = "bottom") +
  guides(color = guide_legend(nrow = 4))

We can see that the regions’ the most affected by the conflicts are : Middle east and north Africa, Sub-Saharan Africa, South Asia, America & the Caribbean, Eastern Europe ans sometimes Caucasus and Central Asia

Now that we could visualize which regions are the most impacted by these three events we can do correlations analysis per region to see if this events have indeed an impact on the evolution of SDG goals.

Here we want to analyse the correlation between the climate disasters and the SDG goals in South and East Asia.

Q3.1[is.na(Q3.1)] <- 0

south_east_asia_data <- Q3.1[Q3.1$region %in% c("South Asia", "East Asia"), ]

relevant_columns <- c("goal1", "goal2", "goal3", "goal4", "goal5", "goal6", "goal7", "goal8", "goal9", "goal10", "goal11", "goal12", "goal13", "goal15", "goal16", "total_affected", "no_homeless")

correlation_matrix_disaster_Asia <- cor(south_east_asia_data[, relevant_columns], use = "complete.obs")

kable(correlation_matrix_disaster_Asia)
goal1 goal2 goal3 goal4 goal5 goal6 goal7 goal8 goal9 goal10 goal11 goal12 goal13 goal15 goal16 total_affected no_homeless
goal1 1.000 -0.026 0.322 0.394 0.186 0.358 0.402 0.537 0.203 0.577 0.170 -0.035 -0.073 0.450 0.125 -0.040 -0.050
goal2 -0.026 1.000 0.647 0.505 0.573 0.547 0.512 0.548 0.679 -0.205 0.520 -0.302 -0.321 -0.280 0.474 0.099 -0.076
goal3 0.322 0.647 1.000 0.789 0.588 0.703 0.826 0.806 0.864 -0.170 0.804 -0.747 -0.725 -0.212 0.719 -0.017 -0.105
goal4 0.394 0.505 0.789 1.000 0.605 0.497 0.630 0.610 0.656 -0.080 0.455 -0.580 -0.604 -0.103 0.373 0.093 -0.014
goal5 0.186 0.573 0.588 0.605 1.000 0.563 0.451 0.453 0.427 -0.100 0.529 -0.404 -0.450 -0.205 0.347 0.055 -0.152
goal6 0.358 0.547 0.703 0.497 0.563 1.000 0.667 0.625 0.693 -0.006 0.655 -0.578 -0.542 -0.135 0.582 -0.128 -0.207
goal7 0.402 0.512 0.826 0.630 0.451 0.667 1.000 0.702 0.760 -0.084 0.809 -0.536 -0.487 -0.208 0.548 -0.024 -0.060
goal8 0.537 0.548 0.806 0.610 0.453 0.625 0.702 1.000 0.741 0.189 0.642 -0.576 -0.563 -0.033 0.639 -0.012 -0.090
goal9 0.203 0.679 0.864 0.656 0.427 0.693 0.760 0.741 1.000 -0.115 0.671 -0.733 -0.730 -0.220 0.660 0.011 -0.067
goal10 0.577 -0.205 -0.170 -0.080 -0.100 -0.006 -0.084 0.189 -0.115 1.000 -0.306 0.182 0.158 0.608 -0.033 -0.150 -0.038
goal11 0.170 0.520 0.804 0.455 0.529 0.655 0.809 0.642 0.671 -0.306 1.000 -0.631 -0.557 -0.354 0.695 -0.123 -0.154
goal12 -0.035 -0.302 -0.747 -0.580 -0.404 -0.578 -0.536 -0.576 -0.733 0.182 -0.631 1.000 0.959 0.139 -0.732 0.112 0.116
goal13 -0.073 -0.321 -0.725 -0.604 -0.450 -0.542 -0.487 -0.563 -0.730 0.158 -0.557 0.959 1.000 0.069 -0.671 0.055 0.096
goal15 0.450 -0.280 -0.212 -0.103 -0.205 -0.135 -0.208 -0.033 -0.220 0.608 -0.354 0.139 0.069 1.000 0.022 -0.071 -0.022
goal16 0.125 0.474 0.719 0.373 0.347 0.582 0.548 0.639 0.660 -0.033 0.695 -0.732 -0.671 0.022 1.000 -0.146 -0.130
total_affected -0.040 0.099 -0.017 0.093 0.055 -0.128 -0.024 -0.012 0.011 -0.150 -0.123 0.112 0.055 -0.071 -0.146 1.000 0.147
no_homeless -0.050 -0.076 -0.105 -0.014 -0.152 -0.207 -0.060 -0.090 -0.067 -0.038 -0.154 0.116 0.096 -0.022 -0.130 0.147 1.000

cor_melted <- as.data.frame(as.table(correlation_matrix_disaster_Asia))
names(cor_melted) <- c("Variable1", "Variable2", "Correlation")

ggplot(data = cor_melted, aes(Variable1, Variable2, fill = Correlation)) +
  geom_tile() +
  scale_fill_gradient2(low = "blue", high = "red", mid = "white",
                       midpoint = 0, limit = c(-1, 1), space = "Lab",
                       name = "Correlation") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, vjust = 1, size = 8, hjust = 1),
        axis.text.y = element_text(size = 8)) +
  coord_fixed() +
  labs(x = '', y = '',
       title = 'Correlation between the climate disasters and the SDG goals in South and East Asia')

We conclude that climate disasters do not really have a big impact on SDG goals.

Here we want to analyse the correlation between the Covid-19 and the SDG goals only during Covid time.

covid_filtered <- Q3.2[Q3.2$year >= as.Date("2019-01-01"), ]

relevant_columns <- c("goal1", "goal2", "goal3", "goal4", "goal5", "goal6", "goal7", "goal8", "goal9", "goal10", "goal11", "goal12", "goal13", "goal15", "goal16", "stringency", "cases_per_million", "deaths_per_million")
# Subset data with relevant columns for correlation analysis
relevant_data <- covid_filtered[, relevant_columns]

correlation_matrix_Covid <- cor(relevant_data, use = "complete.obs")

kable(correlation_matrix_Covid)
goal1 goal2 goal3 goal4 goal5 goal6 goal7 goal8 goal9 goal10 goal11 goal12 goal13 goal15 goal16 stringency cases_per_million deaths_per_million
goal1 1.000 0.534 0.867 0.777 0.445 0.763 0.798 0.584 0.781 0.497 0.727 -0.648 -0.553 0.099 0.714 0.056 0.341 0.361
goal2 0.534 1.000 0.560 0.541 0.469 0.605 0.469 0.636 0.569 0.240 0.463 -0.353 -0.284 0.122 0.451 0.088 0.206 0.242
goal3 0.867 0.560 1.000 0.829 0.641 0.836 0.845 0.693 0.881 0.456 0.828 -0.789 -0.669 0.152 0.825 0.040 0.412 0.373
goal4 0.777 0.541 0.829 1.000 0.656 0.764 0.803 0.596 0.773 0.309 0.758 -0.655 -0.558 0.058 0.674 0.113 0.349 0.339
goal5 0.445 0.469 0.641 0.656 1.000 0.663 0.606 0.587 0.645 0.098 0.690 -0.653 -0.564 0.203 0.628 0.060 0.330 0.261
goal6 0.763 0.605 0.836 0.764 0.663 1.000 0.765 0.711 0.811 0.366 0.766 -0.727 -0.583 0.262 0.729 0.069 0.389 0.398
goal7 0.798 0.469 0.845 0.803 0.606 0.765 1.000 0.556 0.740 0.323 0.793 -0.654 -0.494 0.123 0.697 0.055 0.340 0.374
goal8 0.584 0.636 0.693 0.596 0.587 0.711 0.556 1.000 0.695 0.387 0.587 -0.635 -0.556 0.283 0.627 0.024 0.356 0.278
goal9 0.781 0.569 0.881 0.773 0.645 0.811 0.740 0.695 1.000 0.462 0.753 -0.857 -0.760 0.189 0.819 0.074 0.460 0.353
goal10 0.497 0.240 0.456 0.309 0.098 0.366 0.323 0.387 0.462 1.000 0.281 -0.496 -0.469 0.215 0.519 -0.030 0.262 0.142
goal11 0.727 0.463 0.828 0.758 0.690 0.766 0.793 0.587 0.753 0.281 1.000 -0.696 -0.576 0.089 0.764 0.037 0.345 0.328
goal12 -0.648 -0.353 -0.789 -0.655 -0.653 -0.727 -0.654 -0.635 -0.857 -0.496 -0.696 1.000 0.876 -0.316 -0.825 0.013 -0.466 -0.292
goal13 -0.553 -0.284 -0.669 -0.558 -0.564 -0.583 -0.494 -0.556 -0.760 -0.469 -0.576 0.876 1.000 -0.205 -0.682 -0.018 -0.364 -0.166
goal15 0.099 0.122 0.152 0.058 0.203 0.262 0.123 0.283 0.189 0.215 0.089 -0.316 -0.205 1.000 0.303 -0.068 0.169 0.223
goal16 0.714 0.451 0.825 0.674 0.628 0.729 0.697 0.627 0.819 0.519 0.764 -0.825 -0.682 0.303 1.000 -0.023 0.425 0.316
stringency 0.056 0.088 0.040 0.113 0.060 0.069 0.055 0.024 0.074 -0.030 0.037 0.013 -0.018 -0.068 -0.023 1.000 0.041 0.336
cases_per_million 0.341 0.206 0.412 0.349 0.330 0.389 0.340 0.356 0.460 0.262 0.345 -0.466 -0.364 0.169 0.425 0.041 1.000 0.416
deaths_per_million 0.361 0.242 0.373 0.339 0.261 0.398 0.374 0.278 0.353 0.142 0.328 -0.292 -0.166 0.223 0.316 0.336 0.416 1.000

cor_melted <- as.data.frame(as.table(correlation_matrix_Covid))
names(cor_melted) <- c("Variable1", "Variable2", "Correlation")

ggplot(data = cor_melted, aes(Variable1, Variable2, fill = Correlation)) +
  geom_tile() +
  scale_fill_gradient2(low = "blue", high = "red", mid = "white",
                       midpoint = 0, limit = c(-1, 1), space = "Lab",
                       name = "Correlation") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, vjust = 1, size = 8, hjust = 1),
        axis.text.y = element_text(size = 8)) +
  coord_fixed() +
  labs(x = '', y = '',
       title = 'Correlation between COVID and the SDG goals')

Same conclusion, really weird.

Here we want to analyse the correlation between conflicts deaths and the SDG goals only for the Middle East & North Africa, Sub-Saharan Africa, South Asia, Latin America & the Caribbean and Eastern Europe regions.


# Filter data for specific regions
selected_regions <- c("Middle East & North Africa", "Sub-Saharan Africa", "South Asia", "Latin America & the Caribbean", "Eastern Europe")
conflicts_selected <- Q3.3[Q3.3$region %in% selected_regions, ]

# Select relevant columns for the correlation analysis
relevant_columns <- c("goal1", "goal2", "goal3", "goal4", "goal5", "goal6", "goal7", "goal8", "goal9", "goal10", "goal11", "goal12", "goal13", "goal15", "goal16", "sum_deaths")

# Compute correlation matrix for the selected regions
correlation_matrix_Conflicts_Deaths <- cor(conflicts_selected[, relevant_columns], use = "complete.obs")

# View the correlation matrix
kable(correlation_matrix_Conflicts_Deaths)
goal1 goal2 goal3 goal4 goal5 goal6 goal7 goal8 goal9 goal10 goal11 goal12 goal13 goal15 goal16 sum_deaths
goal1 1.000 0.476 0.910 0.791 0.406 0.799 0.865 0.546 0.723 0.272 0.783 -0.730 -0.594 0.039 0.613 -0.095
goal2 0.476 1.000 0.544 0.531 0.540 0.638 0.531 0.571 0.530 0.102 0.475 -0.376 -0.322 0.154 0.430 -0.173
goal3 0.910 0.544 1.000 0.814 0.507 0.832 0.876 0.596 0.768 0.223 0.828 -0.745 -0.587 0.014 0.666 -0.117
goal4 0.791 0.531 0.814 1.000 0.645 0.748 0.808 0.536 0.696 0.089 0.768 -0.667 -0.533 0.007 0.496 -0.101
goal5 0.406 0.540 0.507 0.645 1.000 0.587 0.539 0.454 0.516 -0.178 0.620 -0.464 -0.351 0.191 0.384 -0.162
goal6 0.799 0.638 0.832 0.748 0.587 1.000 0.812 0.670 0.734 0.137 0.788 -0.711 -0.529 0.187 0.599 -0.166
goal7 0.865 0.531 0.876 0.808 0.539 0.812 1.000 0.539 0.720 0.152 0.841 -0.704 -0.531 0.039 0.566 -0.094
goal8 0.546 0.571 0.596 0.536 0.454 0.670 0.539 1.000 0.609 0.209 0.542 -0.519 -0.389 0.181 0.462 -0.102
goal9 0.723 0.530 0.768 0.696 0.516 0.734 0.720 0.609 1.000 0.300 0.698 -0.759 -0.689 0.137 0.591 -0.077
goal10 0.272 0.102 0.223 0.089 -0.178 0.137 0.152 0.209 0.300 1.000 0.035 -0.297 -0.299 0.118 0.275 0.078
goal11 0.783 0.475 0.828 0.768 0.620 0.788 0.841 0.542 0.698 0.035 1.000 -0.729 -0.570 0.031 0.656 -0.155
goal12 -0.730 -0.376 -0.745 -0.667 -0.464 -0.711 -0.704 -0.519 -0.759 -0.297 -0.729 1.000 0.865 -0.170 -0.666 0.122
goal13 -0.594 -0.322 -0.587 -0.533 -0.351 -0.529 -0.531 -0.389 -0.689 -0.299 -0.570 0.865 1.000 -0.150 -0.493 0.079
goal15 0.039 0.154 0.014 0.007 0.191 0.187 0.039 0.181 0.137 0.118 0.031 -0.170 -0.150 1.000 0.191 -0.063
goal16 0.613 0.430 0.666 0.496 0.384 0.599 0.566 0.462 0.591 0.275 0.656 -0.666 -0.493 0.191 1.000 -0.162
sum_deaths -0.095 -0.173 -0.117 -0.101 -0.162 -0.166 -0.094 -0.102 -0.077 0.078 -0.155 0.122 0.079 -0.063 -0.162 1.000

# Melt the correlation matrix for ggplot2
cor_melted <- as.data.frame(as.table(correlation_matrix_Conflicts_Deaths))
names(cor_melted) <- c("Variable1", "Variable2", "Correlation")

# Create the heatmap
ggplot(data = cor_melted, aes(Variable1, Variable2, fill = Correlation)) +
  geom_tile() +
  scale_fill_gradient2(low = "blue", high = "red", mid = "white",
                       midpoint = 0, limit = c(-1, 1), space = "Lab",
                       name = "Correlation") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, vjust = 1, size = 8, hjust = 1),
        axis.text.y = element_text(size = 8)) +
  coord_fixed() +
  labs(x = '', y = '',
       title = 'Correlation between Conflicts deaths and the SDG goals')

Finally, we want to analyse the correlation between conflicts affected population and the SDG goals only for the Middle East & North Africa, Sub-Saharan Africa, South Asia, Latin America & the Caribbean, Eastern Europe regions and Caucasus and Central Asia.


# Filter data for specific regions (pop_affected)
selected_regions <- c("Middle East & North Africa", "Sub-Saharan Africa", "South Asia", "Latin America & the Caribbean", "Eastern Europe","Caucasus and Central Asia")
conflicts_selected <- Q3.3[Q3.3$region %in% selected_regions, ]

# Select relevant columns for the correlation analysis
relevant_columns <- c("goal1", "goal2", "goal3", "goal4", "goal5", "goal6", "goal7", "goal8", "goal9", "goal10", "goal11", "goal12", "goal13", "goal15", "goal16", "pop_affected")

# Compute correlation matrix for the selected regions
correlation_matrix_Conflicts_Pop_Affected <- cor(conflicts_selected[, relevant_columns], use = "complete.obs")

# View the correlation matrix
kable(correlation_matrix_Conflicts_Pop_Affected)
goal1 goal2 goal3 goal4 goal5 goal6 goal7 goal8 goal9 goal10 goal11 goal12 goal13 goal15 goal16 pop_affected
goal1 1.000 0.476 0.910 0.791 0.406 0.799 0.865 0.546 0.723 0.272 0.783 -0.730 -0.594 0.039 0.613 -0.066
goal2 0.476 1.000 0.544 0.531 0.540 0.638 0.531 0.571 0.530 0.102 0.475 -0.376 -0.322 0.154 0.430 -0.083
goal3 0.910 0.544 1.000 0.814 0.507 0.832 0.876 0.596 0.768 0.223 0.828 -0.745 -0.587 0.014 0.666 -0.058
goal4 0.791 0.531 0.814 1.000 0.645 0.748 0.808 0.536 0.696 0.089 0.768 -0.667 -0.533 0.007 0.496 -0.030
goal5 0.406 0.540 0.507 0.645 1.000 0.587 0.539 0.454 0.516 -0.178 0.620 -0.464 -0.351 0.191 0.384 -0.152
goal6 0.799 0.638 0.832 0.748 0.587 1.000 0.812 0.670 0.734 0.137 0.788 -0.711 -0.529 0.187 0.599 -0.106
goal7 0.865 0.531 0.876 0.808 0.539 0.812 1.000 0.539 0.720 0.152 0.841 -0.704 -0.531 0.039 0.566 -0.071
goal8 0.546 0.571 0.596 0.536 0.454 0.670 0.539 1.000 0.609 0.209 0.542 -0.519 -0.389 0.181 0.462 -0.099
goal9 0.723 0.530 0.768 0.696 0.516 0.734 0.720 0.609 1.000 0.300 0.698 -0.759 -0.689 0.137 0.591 0.000
goal10 0.272 0.102 0.223 0.089 -0.178 0.137 0.152 0.209 0.300 1.000 0.035 -0.297 -0.299 0.118 0.275 0.074
goal11 0.783 0.475 0.828 0.768 0.620 0.788 0.841 0.542 0.698 0.035 1.000 -0.729 -0.570 0.031 0.656 -0.103
goal12 -0.730 -0.376 -0.745 -0.667 -0.464 -0.711 -0.704 -0.519 -0.759 -0.297 -0.729 1.000 0.865 -0.170 -0.666 0.107
goal13 -0.594 -0.322 -0.587 -0.533 -0.351 -0.529 -0.531 -0.389 -0.689 -0.299 -0.570 0.865 1.000 -0.150 -0.493 0.021
goal15 0.039 0.154 0.014 0.007 0.191 0.187 0.039 0.181 0.137 0.118 0.031 -0.170 -0.150 1.000 0.191 -0.108
goal16 0.613 0.430 0.666 0.496 0.384 0.599 0.566 0.462 0.591 0.275 0.656 -0.666 -0.493 0.191 1.000 -0.099
pop_affected -0.066 -0.083 -0.058 -0.030 -0.152 -0.106 -0.071 -0.099 0.000 0.074 -0.103 0.107 0.021 -0.108 -0.099 1.000

# Melt the correlation matrix for ggplot2
cor_melted <- as.data.frame(as.table(correlation_matrix_Conflicts_Pop_Affected))
names(cor_melted) <- c("Variable1", "Variable2", "Correlation")

# Create the heatmap
ggplot(data = cor_melted, aes(Variable1, Variable2, fill = Correlation)) +
  geom_tile() +
  scale_fill_gradient2(low = "blue", high = "red", mid = "white",
                       midpoint = 0, limit = c(-1, 1), space = "Lab",
                       name = "Correlation") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, vjust = 1, size = 8, hjust = 1),
        axis.text.y = element_text(size = 8)) +
  coord_fixed() +
  labs(x = '', y = '',
       title = 'Correlation between Conflicts Affected Population and the SDG goals')

Focus on relationship between SDGs

How are the different SDGs linked? (We want to see if some SDGs are linked in the fact that a high score on one implies a high score on the other, and thus if we can make groups of SDGs that are comparable in that way).

Let’s explore how the different SDG are correlated together by creating a heatmap of the correlation between our variables. We also added a small script to check whether the correlations are significantly different from 0. First, let’s select the SDGs scores.

sdg_scores <- Q4[, c('goal1', 'goal2', 'goal3', 'goal4', 'goal5', 'goal6',
                     'goal7', 'goal8', 'goal9', 'goal10', 'goal11', 'goal12',
                     'goal13', 'goal15', 'goal16', 'goal17')]

We then, initialize the matrices and calculate the correlation, and p-values of each combination of SDGs scores

cor_matrix <- matrix(nrow = ncol(sdg_scores), ncol = ncol(sdg_scores))
p_matrix <- matrix(nrow = ncol(sdg_scores), ncol = ncol(sdg_scores))
rownames(cor_matrix) <- colnames(sdg_scores)
rownames(p_matrix) <- colnames(sdg_scores)
colnames(cor_matrix) <- colnames(sdg_scores)
colnames(p_matrix) <- colnames(sdg_scores)

# Calculate correlation and p-values
for (i in 1:ncol(sdg_scores)) {
  for (j in 1:ncol(sdg_scores)) {
    test_result <- cor.test(sdg_scores[, i], sdg_scores[, j])
    cor_matrix[i, j] <- test_result$estimate
    p_matrix[i, j] <- test_result$p.value}}

We then reshape our data to be able to use the package ggplot2 to create our heatmap.

melted_cor_matrix <-
  melt(cor_matrix)
melted_p_matrix <-
  melt(matrix(as.vector(p_matrix), nrow = ncol(sdg_scores)))

plot_data <- # Combine the datasets
  cbind(melted_cor_matrix, p_value = melted_p_matrix$value)

ggplot(plot_data, aes(Var1, Var2, fill = value)) +
  geom_tile() +
  geom_text(aes(label = sprintf("%.2f", value), color = p_value < 0.05),
            vjust = 1) +
  scale_fill_gradient2(low = "blue", high = "red", mid = "white", 
                       midpoint = 0, limit = c(-1,1), space = "Lab", 
                       name="Pearson\nCorrelation") +
  scale_color_manual(values = c("black", "yellow")) + # black when significant, yellow if not
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1),
        axis.text.y = element_text(angle = 45, hjust = 1),
        legend.position = "none") +
  labs(x = 'SDG Goals', y = 'SDG Goals',
       title = 'Correlation Matrix with Significance Indicator')

Note that as said previously, we assessed the correlations to ascertain if they substantially deviated from zero, setting the significance level at an alpha of 5%. To aid in visualization, we marked any correlations that did not meet this level of significance with a yellow highlight in our graphical representation. The absence of yellow markings on our plot suggests that all Sustainable Development Goal (SDG) scores demonstrate a statistically significant correlation.

We can have a look at the shape of the corelation between the SDGs with the plot function.

plot(sdg_scores)